<template>
  <div>
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <city-list :city="city"
               :cities="cities"
               :hotCities="hotCities"
               :letter="letter"
    >

    </city-list>
    <city-alphabet
      :cities="cities"
      @changeInfo="handleLetterChange"
    >

    </city-alphabet>
  </div>

</template>

<script>
import CityHeader from './component/Header'
import CitySearch from './component/Search'
import CityList from './component/List'
import CityAlphabet from './component/Alphabet'
import axios from 'axios'
export default {
  name: "City",
  components:{
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data(){
    return {
      city:'',
      cities :{},
      hotCities:[],
      letter:''
    }
  },
  mounted(){
    //获取数据
    this.getCityInfo()
  },
  methods:{
    getCityInfo(){
      axios.get('/api/city.json')
        .then(this.handleGetCityInfoSucc)
    },
    handleGetCityInfoSucc(res){
        res = res.data
      if (res.ret && res.data){
        const data = res.data;
         this.city = data.city
        this.cities =data.cities
        this.hotCities = data.hotCities
      }
    },
    handleLetterChange(letter){
      this.letter = letter
    }
  }

}
</script>


<style scoped>

</style>
